{extend name="admin@index_layout"/}
{block name="main"}


<div class="layui-card">
    <div class="layui-card-header">资产列表</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:$auth->check('cmap/add')}"
               data-auth-edit="{:$auth->check('cmap/edit')}"
               data-auth-delete="{:$auth->check('cmap/del')}"
        ></table>
    </div>
</div>

<script type="text/html" id="barTool">
    <a data-open='{:url("edit")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('cmap/edit')?'':'layui-hide'}"
       title="编辑" data-full="true">编辑</a>

    <a href='{:url("del",["catid"=>$catid])}?id={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>

</script>

<script type="text/html" id="picTpl">
    <img style="max-width:80px; max-height:30px;" src="{{d.img}}" data-image="{{d.name}}">
</script>



<!--操作模板-->

{/block}
{block name="script"}
<script>
    var selectElement=null;
    layui.use('yznTable', function () {
        var table = layui.yznTable;
        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            edit_url: "{:url('edit')}",
            delete_url: "{:url('del')}",
        };
        var proviec = {:json_encode($proviec)};
        var cate_list = {:json_encode($cate_list)};
        table.render({
            init: init,
            autoWidth: true,
            toolbar: ['refresh', 'add','delete',[{
                text: '导入',
                url: "{:url('import')}",
                method: 'open',
                auth: 'add',
                class: 'layui-btn layui-btn-sm',
                icon: 'iconfont icon-add',
                extend: 'data-width="950" data-height="600"',
            }],],
            url: '{:url("index")}',
            cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id',align: "center", width: '8%', title: 'ID'},
                    {field: 'cate_id', align: "center", width: '15%', title: '资产类型',
                        hide: true,
                        selectList: cate_list
                    },
                    {field: 'cate_name', align: "center", width: '10%', title: '资产类型', search: false},
                    {field: 'name', align: "center", width: '15%', title: '公告名称', searchOp: 'like'},
                    {field: 'img', width: '15%', align: "center", title: '图片', templet: '#picTpl'},
                    {
                        field: 'province',
                        align: "center",
                        width: '15%',
                        title: '省',
                        hide: true,
                        selectList: proviec
                    },
                    {field: 'city', align: "center", width: '15%', title: '市',hide: true,
                        selectList: {}},
                    {field: 'c_address', align: "center", width: '20%', title: '详细地址'},
                    {field: 'xm_type', align: "center", width: '15%', title: '项目类型',templet: function (d) {
                            if (d.xm_type == 1) {
                                return '<span style="color: black">竞价项目</span>';
                            } else if (d.xm_type == 2) {
                                return '<span style="color: green">推介项目</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {1:'竞价项目',2: '推介项目'}},
                    {
                        field: 'status', align: "center", width: '15%', title: '公告状态', templet: function (d) {
                            if (d.status == 0) {
                                return '<span style="color: green">招商中</span>';
                            } else if (d.status == 1) {
                                return '<span style="color: red">招商结束</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, search: false
                    },
                    {field: 'create_time', align: "center", width: '15%', title: '创建时间', search: 'range'},

                    {fixed: 'right', align: "center", width: '15%', title: '操作', toolbar: '#barTool'}//delete'
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
        console.log(selectElement2);

    });
    function form1(){
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate2')}",//提交URL
                    data: {'id':data.value},//提交的数据
                    success: function(result){
                        if(result.code == 200){
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function(i, val){
                                str += '<option value='+val.id+'>'+val.name+'</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function() {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }




</script>
{/block}